<template>
  <view class="forum-container">
    <!-- 帖子列表 -->
    <view class="post-list">
      <view
        v-for="(post, index) in postList"
        :key="index"
        class="post-card"
        @click="viewPostDetail(post.postId)"
      >
        <!-- 用户信息 -->
        <view class="user-info">
          <u-avatar :src="post.avatar" size="40"></u-avatar>
          <view class="user-meta">
            <text class="nickname">{{ post.userName }}</text>
            <text class="time">{{ post.createTime }}</text>
          </view>
        </view>

        <!-- 帖子内容 -->
        <view class="post-content">
          <text class="post-title">{{ post.title }}</text>
          <text class="post-desc">{{ post.content }}</text>
          <view>{{ post.tag }}</view>
        </view>

        <!-- 统计信息 -->
        <view class="post-stats">
          <view class="stat-item">
            <u-icon
              v-if="item.collected"
              color="#84fa74"
              name="star"
              size="16"
            ></u-icon>
            <u-icon v-else name="star" size="16"></u-icon>

            <!-- <text>{{ post.views }}</text> -->
          </view>
          <view class="stat-item">
            <u-icon
              v-if="item.liked"
              color="#84fa74"
              name="thumb-up"
              size="16"
            ></u-icon>
            <u-icon v-else name="thumb-up" size="16"></u-icon>
            <!-- <text>{{ post.likes }}</text> -->
          </view>
          <view class="stat-item">
            <u-icon name="chat" size="16"></u-icon>
            <text>{{ post.comments }}</text>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import { getMyList_API } from "../../api/forum";
export default {
  data() {
    return {
      searchKeyword: "",
      currentCategory: 0,
      // 帖子列表
      postList: [],
    };
  },
  methods: {
    viewPostDetail(id) {
      this.$to("/pages/forumInfo/index", { id });
    },
    // 获取帖子列表
    async getForumList() {
      const res = await getMyList_API();
      this.postList = res || [];
    },
  },
  onLoad(options) {
    this.getForumList();
  },
};
</script>

<style lang="scss" scoped>
.forum-container {
  padding: 20rpx;
}

.search-box {
  margin-bottom: 30rpx;
}

.post-list {
  .post-card {
    padding: 30rpx;
    margin-bottom: 30rpx;
    border-radius: 12rpx;
    background-color: #fff;
    box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.05);

    .user-info {
      display: flex;
      align-items: center;
      margin-bottom: 20rpx;

      .user-meta {
        margin-left: 20rpx;
        display: flex;
        flex-direction: column;

        .nickname {
          font-size: 28rpx;
          color: #333;
          font-weight: bold;
        }

        .time {
          font-size: 24rpx;
          color: #999;
          margin-top: 5rpx;
        }
      }
    }

    .post-content {
      margin-bottom: 30rpx;

      .post-title {
        display: block;
        font-size: 32rpx;
        color: #333;
        font-weight: bold;
        margin-bottom: 15rpx;
      }

      .post-desc {
        display: block;
        font-size: 28rpx;
        color: #666;
        line-height: 1.6;
        // @include u-line-clamp(2);
      }
    }

    .post-stats {
      display: flex;
      align-items: center;
      font-size: 24rpx;
      color: #999;

      .stat-item {
        display: flex;
        align-items: center;
        margin-right: 30rpx;

        text {
          margin-left: 8rpx;
        }
      }
    }
  }
}

.shopping-fixed {
  width: 100rpx;
  height: 100rpx;
  background-color: #4db366;
  border-radius: 50%;
  position: fixed;
  right: 50rpx;
  bottom: 50rpx;
  z-index: 999;

  .shopping-fixed-view {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;

    image {
      width: 60rpx;
      height: 60rpx;
    }
  }
}
</style>
